﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using Yunwei.BizLogic;
using Yunwei.Domain.Models;
using Yunwei.IBizLogic;

namespace Yunwei.Web.Areas.Admin.Models
{
    public class CustomerViewModel
    {
        private IRestaurantService _restaurantService;
        private IVendorService _vendorService;
        public CustomerViewModel()
        {
            _restaurantService = new RestaurantService();
            _vendorService = new VendorService();
        }

        public int Id { get; set; }
        public int Vendor_Id { get; set; }
        public int Restaurant_Id { get; set; }

        [Display(Name="供货商状态")]
        public short Vendor_Status { get; set; }

        [Display(Name = "餐厅状态")]
        public short Restaurant_Status { get; set; }

        public string RestaurantStatus
        { 
            get
            {
                if (this.Restaurant_Status == 0)
                    return "fa-times red";
                else
                    return "fa-check green";
            }
        }
        public string VendorStatus
        {
            get
            {
                if (this.Vendor_Status == 0)
                    return "fa-times red";
                else
                    return "fa-check green";
            }
        }

        public bool BindStatus
        {
            get
            {
                return this.Vendor_Status == 1 && this.Restaurant_Status == 1;
            }
        }

        private Restaurant _restaurant;
        public Restaurant Restaurant
        {
            get
            {
                if (_restaurant == null)
                    _restaurant = _restaurantService.Find(Restaurant_Id);
                return _restaurant;
            }
        }

        private Vendor _vendor;
        public Vendor Vendor
        {
            get
            {
                if (_vendor == null)
                    _vendor = _vendorService.Find(Vendor_Id);
                return _vendor;
            }
        }


        public static CustomerViewModel FromVendorCustomer(VendorCustomer vc)
        {
            CustomerViewModel cvm = new CustomerViewModel();
            if (vc == null) return cvm;

            cvm.Id = vc.Id;
            cvm.Vendor_Id = vc.Vendor_Id;
            cvm.Restaurant_Id = vc.Restaurant_Id;
            cvm.Vendor_Status = vc.Vendor_Status;
            cvm.Restaurant_Status = vc.Restaurant_Status;
            return cvm;
        }

        public VendorCustomer VendorCustomer
        {
            get
            {
                VendorCustomer vc = new VendorCustomer()
                {
                    Id = this.Id,
                    Restaurant_Id = this.Restaurant_Id,
                    Restaurant_Status = this.Restaurant_Status,
                    Vendor_Id = this.Vendor_Id,
                    Vendor_Status = this.Vendor_Status
                };

                return vc;
            }
        }



        //[Required(ErrorMessage = "必填")]
        //[StringLength(20, MinimumLength = 4, ErrorMessage = "{2}到{1}个字符")]
        //[Display(Name = "用户名")]
        //public string Name { get; set; }
        //[Required(ErrorMessage = "必填")]
        //[StringLength(200, MinimumLength = 5, ErrorMessage = "{2}到{1}个字符")]
        //[Display(Name = "门头照片")]
        //public string Avatar { get; set; }

        //[Required(ErrorMessage = "必填")]
        //[StringLength(200, MinimumLength = 4, ErrorMessage = "{2}到{1}个字符")]
        //[Display(Name = "地址")]
        //public string Address { get; set; }

        //[Required(ErrorMessage = "必填")]
        //[StringLength(20, MinimumLength = 8, ErrorMessage = "{2}到{1}个字符")]
        //[Display(Name = "电话")]
        //public string Phone { get; set; }

        //[Required(ErrorMessage = "必填")]
        //[Display(Name = "经度")]
        //public decimal X { get; set; }

        //[Required(ErrorMessage = "必填")]
        //[Display(Name = "纬度")]
        //public decimal Y { get; set; }

        //[Required(ErrorMessage = "必填")]
        //[Display(Name = "详述")]
        //public string Description { get; set; }
    }
}